package com.hanlan.springboot.controller;

import com.hanlan.springboot.entity.Student;
import com.hanlan.springboot.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @description: Controller 测试类
 * @author: 01369542
 * @create: 2018/11/15
 **/
@Slf4j
@RestController
@EnableAutoConfiguration
@RequestMapping("/student")
public class StudentController {

    private static final Logger logger = LoggerFactory.getLogger(StudentController.class);

    @Autowired
    private StudentService studentService;

    @RequestMapping("/getAllStudents")
    public List<Student> getAllStudents() {
        return studentService.getAllStudents();
    }

    @RequestMapping("/getStudentById")
    @ResponseBody
    public Student getStudentById(HttpServletRequest request) {
        String idStr=request.getParameter("id");
        if(StringUtils.isEmpty(idStr))throw new RuntimeException("id is null.");

        Integer id = Integer.parseInt(idStr);
        Student student = studentService.selectByPrimaryKey(id);
        return student;
    }

}
